<template>
  <div class="container">
    <div class="header">
     
      <!-- 将卡片放入 header 内，并使用 v-show 控制显示 -->
      <div class="card" v-for="(card, index) in cards" :key="index" v-show="activeCard === index">
        <div class="card-header">{{ card.title }}
          <span v-if="activeCard === 1">&#128065;</span> <!-- 小眼睛图标 -->
        </div>
        <div class="main-content">
          <p class="rate">{{ card.content }}</p>
        </div>
      </div>

      <!-- 根据卡片索引显示不同的按钮或图标 -->
      <div v-if="activeCard === 0">
        <button @click="changeCard(1)">点击登录</button>
      </div>
      <div v-else-if="activeCard === 1">
       
        <div class="icon-item" @click="changeCard(2)" title="切换到昨日收益（元）">
          <font-awesome-icon :icon="['fas', 'arrow-right']" />
        </div>
      </div>
      <div v-else-if="activeCard === 2">
  
        <div class="icon-item" @click="changeCard(3)" title="切换到昨日收益（元）">
          <font-awesome-icon :icon="['fas', 'arrow-right']" />
        </div>
      </div>
      <div v-else-if="activeCard === 3">
       
        <div class="icon-item" @click="changeCard(0)" title="切换到登录查看资产情况">
          <font-awesome-icon :icon="['fas', 'arrow-left']" />
        </div>
      </div>
    </div>

    <div class="card flex-container">
      <div class="icon-item" @click="navigateTo('/finance')" title="理财">
        <img class="btn-img" src="./assets_page3/pig.svg" />
        
        <span>理财</span>
      </div>
      <div class="icon-item" @click="navigateTo('/fund')" title="基金">
        <img class="btn-img" src="./assets_page3/jijin.svg" />
      
        <span>基金</span>
      </div>
      <div class="icon-item" @click="navigateTo('/risk-evaluation')" title="风险评估">
        <img class="btn-img" src="./assets_page3/fengxian.svg" />
        
        <span>风险评估</span>
      </div>
      <div class="icon-item" @click="navigateTo('/more')" title="更多">
        <img class="btn-img" src="./assets_page3/more.svg" />

        <span>更多</span>
      </div>
    </div>

    <div class="layout-container">
      <div class="main-card flexible-card">
        <div class="card-header">灵活理财</div>
        <div class="main-content">
          <p class="rate">1.719%</p>
          <p>近七日年化</p>
          <div class="tags">
            <span>中低风险</span>
            <span>每日开放</span>
          </div>
          <a href="#" class="info-button">了解更多 ></a>
        </div>
      </div>
      <div class="side-cards">
        <div class="side-card">
          <div class="card-header">稳健理财</div>
          <div class="main-content">
            <p class="rate">2.40% - 3.20%</p>
            <div class="tags">
              <span>中低风险</span>
              <span>每日开放</span>
            </div>
          </div>
        </div>
        <div class="side-card">
          <div class="card-header">优选基金</div>
          <div class="main-content">
            <p class="rate">10.36%</p>
            <div class="tags">
              <span>T+3赎回</span>
              <span>高风险</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="wealth-card">
      <div class="content">
        <h3>点击获取我的财富“通”关图</h3>
        <p>一键获取资产配置报告</p>
        <button class="action-button">点击查看</button>
      </div>
      <div class="image-container">
        <div class="image" style="display: flex; flex-direction: column;">
          <img src="./assets_page3/youxiajiao.png" alt="财富图" />
          <img src="./assets_page3/youxiajiao (2).png" alt="财富图" />
        </div>
        <div class="bottom-left-image">
          <img src="./assets_page3/zuoxiajiao.png" alt="新图片" class="small-image positioned-image" />
        </div>
      </div>
    </div>

    <!-- 插入新的热点推荐卡片 -->
    <div class="layout-container">
      <div class="main-card">
        <div class="card-header">热点推荐</div>
        <div class="list">
          <div class="item">
            <span class="item-number">1</span>历史上首个“特大地震...<span class="item-label label-explosion">爆</span>
          </div>
          <div class="item">
            <span class="item-number">2</span>巴黎奥运会落幕式...<span class="item-label label-hot">热</span>
          </div>
          <div class="item">
            <span class="item-number">3</span>养老新选择！找不到...<span class="item-label label-new">新</span>
          </div>
        </div>
        <a href="#" class="link">更多热点 ></a>
      </div>
      
      <div class="side-cards">
        <div class="side-card">
          <div class="card-header">教你理财轻松入门</div>
          <div class="main-content">
            <p class="rate">1.719%</p>
            <p>近七日年化</p>
            <div class="tags">
              <span>中低风险</span>
              <span>每日开放</span>
            </div>
            <a href="#" class="info-button">了解更多 ></a>
          </div>
        </div>
        <div class="side-card">
          <div class="card-header">智慧城市科技金融</div>
          <div class="main-content">
            <p class="rate">2.40% - 3.20%</p>
            <p>每月可赎 中低风险</p>
          </div>
        </div>
      </div>
    </div>

    <div class="footer">
      <p style="text-align:center;">葫芦娃银行</p>
    </div>
  </div>
</template>

<script>
import { Icon } from 'vant';
import { library } from '@fortawesome/fontawesome-svg-core';
import { fas } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';

library.add(fas);

export default {
  components: {
    [Icon.name]: Icon,
    FontAwesomeIcon,
  },
  data() {
    return {
      activeCard: 0,
      cards: [
        { title: "登录查看资产情况" },
        { title: "账户资产（折算人民币）", content: "999,999.99" },
        { title: "昨日收益（元）", content: "******" },
        { title: "昨日收益（元）", content: "10,000.00" },
      ],
    };
  },
  methods: {
    changeCard(index) {
      try {
        this.activeCard = index;
        console.log('当前激活的卡片索引:', this.activeCard);
      } catch (error) {
        console.error('切换卡片时发生错误:', error);
      }
    },
    navigateTo(page) {
      try {
        this.$router.push(page);
      } catch (error) {
        console.error('导航时发生错误:', error);
      }
    },
  },
};
</script>

<style scoped>
.small-image {
  width: 50px;
  height: auto;
}

.positioned-image {
  margin-left: -800px;
}

.image-container {
  position: relative;
  display: flex;
  justify-content: left;
}

.image {
  display: flex;
  flex-direction: column;
}

.bottom-left-image {
  position: absolute;
  bottom: 0;
  left: 0;
}

.container {
  width: 90%;
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  background: linear-gradient(to bottom, #d9eddb, #f5fffa);
}

.card-header {
  font-weight: bold;
  margin-bottom: 10px;
  position: relative;
  background-color: transparent;
}
/* 卡片标题背景图 */
.card-header::after {
  content: ''; /* 伪元素必须有 content 属性 */
  position: absolute;
  top: 0;
  right: 0; /* 调整这个值来控制背景的位置 */
  bottom: 0;
  left: 100%; /* 背景在文字后面 */
  background-image: url('./assets_page3/zitibeijingtu.svg');
  background-size: contain; /* 根据需要调整背景大小 */
  background-repeat: no-repeat;
  background-position: right; /* 背景图像靠右 */
}
.card-header span {
  margin-left: 10px;
  font-size: 1.2em;
  
}

.header {
  width: 100%;
  height: 240px;
  background-image: url('./assets_page3/dingbu.svg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.header h2 {
  font-size: 24px;
  text-align: center;
  margin: 20px auto;
  padding-top: 60px;
}

.header button {
  background-color: #4aa44a;
  border: none;
  padding: 10px 20px;
  cursor: pointer;
  border-radius: 5px;
}

.icon-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  margin: 10px;
}
.flexible-card {
  position: relative;
  /* background-image: url('./assets_page3/zitibeijingtu.svg'); */
  background-size: contain; /* 确保图片完整显示 */
  background-repeat: no-repeat;
  background-position: center; /* 调整为适当位置 */}
/* 灵活理财卡片 */
.flex-container {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}

.layout-container {
  display: flex;
  justify-content: space-between;
  padding: 20px;
  background-color: #f8f8f8;
}

.main-card {
  background-color: #fffbe6;
  border-radius: 10px;
  padding: 20px;
  flex: 1;
  margin-right: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.side-cards {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.side-card {
  background-color: #fff;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.card-header {
  font-weight: bold;
  padding: 10px;
  border-radius: 5px;
  text-align: center;
  margin-bottom: 10px;
}

.main-content {
  text-align: center;
}

.rate {
  font-size: 2em;
  color: #e74c3c;
  margin: 10px 0;
}

.tags span {
  display: inline-block;
  background-color: #f1c40f;
  color: #fff;
  padding: 5px 10px;
  border-radius: 5px;
  margin: 5px;
}

.info-button {
  display: inline-block;
  margin-top: 10px;
  padding: 10px;
  background-color: #babdc0;
  color: #fff;
  border-radius: 5px;
  text-decoration: none;
}

.wealth-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(to right, #f7f0c3, #fce1c8);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin: 20px 0;
}

.content {
  flex: 1;
}

.content h3 {
  font-size: 1.5em;
  color: #333;
  margin: 0;
  font-weight: bold;
}

.content p {
  color: #555;
  margin: 10px 0;
}

.action-button {
  display: inline-block;
  padding: 10px 20px;
  background-color: #f49b42;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  text-align: center;
}

.image {
  flex-shrink: 0;
  margin-left: 20px;
}

.image img {
  width: 100px;
  height: auto;
}

.footer {
  text-align: center;
  margin-top: 20px;
}

.large-icon {
  font-size: 3em;
}

.more-hotspots {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.more-hotspots .info-button {
  margin-left: auto;
}

.list {
  background-color: #fff;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
}

.item {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
}

.item-number {
  color: #e74c3c;
  margin-right: 5px;
}

.item-label {
  color: #fff;
  border-radius: 12px;
  padding: 2px 6px;
  font-size: 0.8em;
  margin-left: auto;
}

.label-explosion {
  background-color: #e74c3c;
}

.label-hot {
  background-color: #e74c3c;
}

.label-new {
  background-color: #3498db;
}

.link {
  text-align: right;
  color: #3498db;
  text-decoration: none;
  display: inline-block;
}
</style>
